{ Russian Olympiad. 2 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/roi/stage2/roi_2stage.pdf
  Problem 4
  Points: 56
}
{$APPTYPE CONSOLE}
const module=1000000007;
var n,s,max,x,count,res:int64; data:array[1..1001,1..1001] of byte; dob,port:array[1..1001] of int64; ports:array[1..1001] of int64; i,j:longint;
function find(v:integer):int64;
var i,count,j:integer; cur:array[1..1001] of int64; res:int64;
begin
res:=0;
count:=0;
for I := 1 to n-1 do if data[v,i]=1 then begin
  inc(count);
  cur[count]:=find(i);
end;
for I := 1 to count-1 do
  for j := i+1 to count do res:=(res+cur[i]*cur[j]) mod module;
res:=(res+dob[v]) mod module;
find:=res;
end;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
for i := 1 to n do begin
  for j := 1 to n do data[i,j]:=0;
  dob[i]:=0;
  port[i]:=0;
end;
for I := 1 to n-1 do begin
  readln(x,dob[i]);
  data[i,x]:=1;
end;
readln(dob[n]);
count:=0;
for I := 1 to n-1 do begin
  if data[i,n]=1 then begin
    inc(count);
    ports[count]:=find(i);
  end;
end;
res:=0;
for I := 1 to count-1 do
  for j := i+1 to count do res:=(res+ports[i]*ports[j]) mod module;
inc(res,dob[n]);
res:=res mod module;
writeln(res);
close(input);
close(output);
end.
